package com.xiehua.task.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xiehua.task.domain.ConfigClientDO;
import com.xiehua.task.service.ConfigClientService;
import com.xiehua.common.utils.PageUtils;
import com.xiehua.common.utils.Query;
import com.xiehua.common.utils.R;

/**
 * 任务客户端配置信息表
 * 
 * @author Mr.zhang
 * @email 562464314@qq.com
 * @date 2018-07-10 17:34:21
 */
 
@Controller
@RequestMapping("/task/configClient")
public class ConfigClientController {
	@Autowired
	private ConfigClientService configClientService;
	
	@GetMapping()
	@RequiresPermissions("task:configClient:configClient")
	String ConfigClient(){
	    return "task/configClient/configClient";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("task:configClient:configClient")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<ConfigClientDO> configClientList = configClientService.list(query);
		int total = configClientService.count(query);
		PageUtils pageUtils = new PageUtils(configClientList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("task:configClient:add")
	String add(){
	    return "task/configClient/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("task:configClient:edit")
	String edit(@PathVariable("id") Integer id,Model model){
		ConfigClientDO configClient = configClientService.get(id);
		model.addAttribute("configClient", configClient);
	    return "task/configClient/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("task:configClient:add")
	public R save( ConfigClientDO configClient){
		if(configClientService.save(configClient)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("task:configClient:edit")
	public R update( ConfigClientDO configClient){
		configClientService.update(configClient);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("task:configClient:remove")
	public R remove( Integer id){
		if(configClientService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("task:configClient:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] ids){
		configClientService.batchRemove(ids);
		return R.ok();
	}

    /**
     * 任务列表
     */
    @GetMapping( "/tasklist")
    @ResponseBody
    @RequiresPermissions("task:configClient:tasklist")
    public String tasklist(@RequestParam Map<String, Object> params,Model model){
        //查询列表数据
        Query query = new Query(params);
        List<ConfigClientDO> configClientList = configClientService.list(query);
        int total = configClientService.count(query);
        PageUtils pageUtils = new PageUtils(configClientList, total);

        model.addAttribute("bContent", pageUtils);
        return "task/onfigClient/configClient";
    }
	
}
